package com.onlineMIS.ORM.DAO.headQ.barCodeGentor;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.onlineMIS.ORM.DAO.BaseDAO;
import com.onlineMIS.ORM.entity.headQ.barcodeGentor.Menu;
import com.onlineMIS.ORM.entity.headQ.barcodeGentor.ProductBarcode;


@Repository
public class MenuDaoImpl extends BaseDAO<Menu> {
	
	
	
	/**
	 * 根据菜单级别查询菜单集合信息
	 * @param level
	 * @return
	 */
	public List<Menu> getMenusByLevel(String level) {
		DetachedCriteria criteria = DetachedCriteria.forClass(Menu.class);
		criteria.add(Restrictions.eq("menuType", level));
		criteria.add(Restrictions.eq("status", Menu.STATUS_NORMAL));	
		criteria.addOrder(Order.asc("sort"));		
		List<Menu> menus =  this.getByCritera(criteria,true);
		return menus;
	}
	

	/**
	 * 根据菜单父级ID查询菜单集合信息
	 * @param menuId
	 * @return
	 */
	public List<Menu> getMenusByParentId(Integer menuId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(Menu.class);
		criteria.add(Restrictions.eq("parentId", menuId));
		criteria.add(Restrictions.eq("status", Menu.STATUS_NORMAL));	
		criteria.addOrder(Order.asc("sort"));
		List<Menu> menus =  this.getByCritera(criteria,true);
		return menus;
	}


	/**
	 * 根据菜单路径，查询是否存在该菜单
	 * @param menuPath
	 * @return
	 */
	public boolean selectMenuByPath(String menuPath) {
		DetachedCriteria criteria = DetachedCriteria.forClass(Menu.class);
		criteria.add(Restrictions.eq("menuPath", menuPath));		
		List<Menu> menus =  this.getByCritera(criteria,true);
		if (menus.size() != 0) {
			return true;
		}else {
			return false;
		}
	}


	/**
	 * 根据菜单ID集合查询菜单信息
	 * @param menuIds
	 * @return
	 */
	public List<Menu> getMenusByIds(List<Integer> menuIds) {
		DetachedCriteria criteria = DetachedCriteria.forClass(Menu.class);
		criteria.add(Restrictions.in("id", menuIds));		
		List<Menu> menus =  this.getByCritera(criteria,true);
		return menus;
	}


	/**
	 * 根据菜单路径查询菜单信息
	 * @param path
	 * @return
	 */
	public Menu getMenusByPath(String path) {
		DetachedCriteria criteria = DetachedCriteria.forClass(Menu.class);
		criteria.add(Restrictions.eq("menuPath", path));		
		List<Menu> menus =  this.getByCritera(criteria,true);
		if (menus.size() != 0) {
			return menus.get(0);
		}else {
			return null;
		}
	}

}
